<!DOCTYPE html>
<html class="x-admin-sm">
    <head>
        <meta charset="UTF-8">
        <title>菜单管理</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="stylesheet" href="./css/font.css">
        <link rel="stylesheet" href="./css/index.css">
        <script src="./lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="./js/index.js"></script>

    </head>
    <style>
    	html{
    		overflow-x: auto;
    	}
    	
    	#memutypeid{
padding: 5px;
border: 1px solid #c1b2b2;
    	}
    </style>
    <body>
        <div class="x-nav">
          <span class="layui-breadcrumb">
            <a >首页</a>
            <a >演示</a>
            <a>
              <cite>导航元素</cite></a>
          </span>
          <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
            <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
        </div>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body ">
                              选择菜单类型                       
                              
                                	
                                    <select  id="memutypeid">                     	
                                    	
                                    </select>
                              
                                <div class="layui-inline layui-show-xs-block" onclick="selects()">
                                    <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
                                </div>
                           
                        </div>
                        <div class="layui-card-header">
                         
                            <button class="layui-btn" onclick="xadmin.open('添加菜单','./memu-add.html',600,400);"><i class="layui-icon"></i>添加</button>
                        </div>
                        <div class="layui-card-body ">
                            <table class="layui-table layui-form">
                              <thead>
                                <tr>
                                  
                                  <th>ID</th>
                                  <th>菜单名</th>                    
                                  <th style="min-width: 120px;">描述</th>
                                  <th style="min-width: 400px;">样式</th>
                                  <th style="min-width: 120px;">图片</th>
                                  <th>URL</th>
                                  <th>菜单类型</th>
                                  <th>跳转方式</th>
                                  <th>菜单等级</th>
                                  <th>父菜单ID</th>
                                  <th>登录时名字</th>
                                  <th>登录时URL</th>
                                  <th style="min-width: 120px;">登录时图片</th>
                                  <th>创建时间</th>
                                  <th>修改时间</th>
                                   <th>状态</th>
                                  <th>操作</th>
                              </thead>
                              <tbody id="table">
                               
                                
                              </tbody>
                            </table>
                        </div>
                      
                    </div>
                </div>
            </div>
        </div> 
    </body>
   <script src="js/jquery.js"></script>
    <script type="application/javascript">
      selects();
    	//模糊查询
    	function selects(){
    		
    		$.ajax({
    			type:"get",
    			url:"http://localhost:16111/memurbac/reachmemu",
    			xhrFields:{withCredentials: true},
    			dataType:"json",    			
    			data:{typeid:$("#memutypeid").val()},
    			success:function(res){
    				//表示为查询成功，
    				if(res.code==200){
    					//表格头部不去除
    					$("table tr:not(:first)").html("");
    					//将数据添加到table中
    					for(var i=0;i<res.data.memus.length;i++){
    						   
    						  
                                  if(res.data.memus[i].memu_status==1){
                                  	res.data.memus[i].memu_status="已停用";
                                  	 var title="停用";
                                  	 var ihtml='&#xe62f;';
                                  	 var cla="layui-btn layui-btn-normal layui-btn-mini layui-btn-disabled";
                                  }else{
                                  	res.data.memus[i].memu_status="已启用";
                                  	var title="启用";
                                  	var ihtml='&#xe601;';
                                  	var cla="layui-btn layui-btn-normal layui-btn-mini ";
                                  }
                                  
                                  
                                  if(res.data.memus[i].memu_skiptype==1){
                                  	var skiptype="新页面"
                                  }else{
                                  	var skiptype="本页面"
                                  }
                                  
                                  
                                    if(res.data.memus[i].memu_grade==1){
                                  	var grade="一级菜单"
                                  }else if(res.data.memus[i].memu_grade==2){
                                  	var grade="二级菜单"
                                  }else if(res.data.memus[i].memu_grade==3){
                                  	var grade="三级菜单"
                                  }else if(res.data.memus[i].memu_grade==4){
                                  	var grade="四级菜单"
                                  }else {
                                  	var grade="五级菜单"
                                  }
                                  
                                  
                                 
			     var str="<tr>"+                                
	                      "<td>"+res.data.memus[i].id+"</td>"+
	                      "<td>"+res.data.memus[i].memu_name+"</td>"+	
	                      "<td>"+res.data.memus[i].memu_desc+"</td>"+	                      
	                      "<td>"+res.data.memus[i].memu_style+"</td>"+
	                       "<td><a  style=\"color: blue;\" target=\"_blank\" href=\""+res.data.memus[i].memu_picture+"\">"+res.data.memus[i].memu_picture+"</a></td>"+ 
	                      "<td>"+res.data.memus[i].memu_url+"</td>"+
	                      "<td>"+res.data.memus[i].memu_typename+"</td>"+
	                      "<td>"+skiptype+"</td>"+
	                      "<td>"+grade+"</td>"+
	                      "<td>"+res.data.memus[i].memu_parentid+"</td>"+
	                      "<td>"+res.data.memus[i].memu_logname+"</td>"+	
	                       "<td>"+res.data.memus[i].memu_logurl+"</td>"+
	                        "<td><a  style=\"color: blue;\" target=\"_blank\" href=\""+res.data.memus[i].memu_logpicture+"\">"+res.data.memus[i].memu_logpicture+"</a></td>"+ 
	                      "<td>"+formatDateTime(res.data.memus[i].memu_createtime)+"</td>"+
	                     "<td>"+formatDateTime(res.data.memus[i].memu_modiftime)+"</td>"+ 
	                      "<td class=\"td-status\"><span class=\""+cla+"\">"+res.data.memus[i].memu_status+"</span></td>"+
	                      "<td class=\"td-manage\">"+
	                        "<a onclick=\"member_stop(this,"+res.data.memus[i].id+")\" href=\"javascript:;\"  title=\""+title+"\">"+
	                          "<i class=\"layui-icon\">"+ihtml+"</i>"+
	                        "</a>"+
	                        "<a title=\"编辑\"  onclick=\"xadmin.open('编辑',\'memu-update.html?memuid="+res.data.memus[i].id+"\')\" href=\"javascript:;\">"+
	                          "<i class=\"layui-icon\"> &#xe642;</i>"+
	                       "</a>"+
	                        "<a title=\"删除\" onclick=\"member_del(this,'"+res.data.memus[i].id+"')\" href=\"javascript:;\">"+	                 
	                          "<i class=\"layui-icon\"> &#xe640;</i>"+
	                        "</a>"+
	                      "</td>"+
	                      "</tr>"
		    	
      
        
  	
                      $('#table').html($('#table').html()+str);
   }
    					
    					$('#memutypeid').html("");
    					
    					//添加可查询菜单类型
    					for(var j in res.data.memutypes){
    						
    						var str1="<option value=\""+res.data.memutypes[j].id+"\">"+res.data.memutypes[j].mt_name+"</option>"
    					$('#memutypeid').html($('#memutypeid').html()+str1);
    					}
    					
    					        
    					
    				}else{
    					
    					layui.use("layer", function () {
                //提示错误信息
    					layer.msg(res.error,{icon:7,time:1000});
             })

    					
    				
    				}
    			},
    			error:function(error){
    			
    				layui.use("layer", function (){
             	//提示错误信息
    				layer.msg(JSON.stringify(error),{icon:2,time:1000});
             })
    				
    			}
    		});
   
    	}
    	
    	
      layui.use(['laydate','form'], function(){
        var laydate = layui.laydate;
        var form = layui.form;
        
        //执行一个laydate实例
        laydate.render({
          elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
          elem: '#end' //指定元素
        });
      });

       /*用户-停用*/
      function member_stop(obj,id){
      	
      	if($(obj).attr('title')=='启用'){
      		var stat='确认要停用吗？';
      	}else{
      		var stat='确认要启用吗？';
      	}
      	
          layer.confirm(stat,function(index){

              if($(obj).attr('title')=='启用'){

                //发异步把用户状态进行更改
                		$.ajax({
    			type:"get",
    			url:"http://localhost:16111/memurbac/offMemu",
    			xhrFields:{withCredentials: true},
    			dataType:"json",    			
    			data:{memuid:id},
    			success:function(res){
    				//表示更改状态成功
    				if(res.code==200){
    			    	$(obj).attr('title','停用')
                       $(obj).find('i').html('&#xe62f;');

                      $(obj).parents("tr").find(".td-status").find('span').addClass('layui-btn-disabled').html('已停用');
                     layer.msg('已停用!',{icon: 5,time:1000});
    
    				}else{
    					
    					layui.use("layer", function () {
                //提示错误信息
    					layer.msg(res.error,{icon:7,time:1000});
             })

    					
    				
    				}
    			},
    			error:function(error){
    			
    				layui.use("layer", function (){
             	//提示错误信息
    				layer.msg(JSON.stringify(error),{icon:2,time:1000});
             })
    				
    			}
    				
    		});
                
                
                

              }else{
              	
              	 		$.ajax({
    			type:"get",
    			url:"http://localhost:16111/memurbac/onMemu",
    			xhrFields:{withCredentials: true},
    			dataType:"json",    			
    			data:{memuid:id},
    			success:function(res){
    				//表示更改状态成功
    				if(res.code==200){
    			    $(obj).attr('title','启用')
                $(obj).find('i').html('&#xe601;');

                $(obj).parents("tr").find(".td-status").find('span').removeClass('layui-btn-disabled').html('已启用');
                layer.msg('已启用!',{icon: 6,time:1000});
    
    				}else{
    					
    					layui.use("layer", function () {
                //提示错误信息
    					layer.msg(res.error,{icon:7,time:1000});
             })

    					
    				
    				}
    			},
    			error:function(error){
    			
    				layui.use("layer", function (){
             	//提示错误信息
    				layer.msg(JSON.stringify(error),{icon:2,time:1000});
             })
    				
    			}
    				
    		});
                
              }
              
          });
      }

      /*用户-删除*/
      function member_del(obj,id){
          layer.confirm('确认要删除吗？',function(index){
              //发异步删除数据
              	$.ajax({
    			type:"get",
    			url:"http://localhost:16111/memurbac/delmemu",
    			xhrFields:{withCredentials: true},
    			dataType:"json",    			
    			data:{memuid:id},
    			success:function(res){
    				//表示删除角色成功
    				if(res.code==200){
    			           $(obj).parents("tr").remove();
                           layer.msg(res.data,{icon:1,time:1000});
                          
    
    				}else{
    					//提示错误信息
    					layer.msg(res.error,{icon:2,time:1000});
    				}
    			},
    			error:function(error){
    				//提示错误信息
    				layer.msg(JSON.stringify(error),{icon:2,time:1000});
    			}
    				
    		});
              
          });
      }
    
      /**
 * 时间转字符串的方法
 */
function formatDateTime(inputTime) {
    var date = new Date(inputTime);
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    m = m < 10 ? ('0' + m) : m;
    var d = date.getDate();
    d = d < 10 ? ('0' + d) : d;
    var h = date.getHours();
    h = h < 10 ? ('0' + h) : h;
    var minute = date.getMinutes();
    var second = date.getSeconds();
    minute = minute < 10 ? ('0' + minute) : minute;
    second = second < 10 ? ('0' + second) : second;
    return y + ' 年 ' + m + ' 月 ' + d + ' 日 ' + h + ' : ' + minute + ' : ' + second;
}
    </script>
    
</html>